package weaver.interfaces.cese.duss.ceseutil;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import weaver.alioss.AliOSSObjectManager;
import weaver.common.DateUtil;
import weaver.conn.ConnStatement;
import weaver.conn.RecordSet;
import weaver.file.AESCoder;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.zip.ZipInputStream;


/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-12-29
 * @Description: ORC浪潮接口
 * @ModifyLog:
 **/

public class OcrUitl {
    //post http
    public static String sendPostHttpOCR(String urlString, int fileIds, String API_KEY) {
        BaseBean baseBean = new BaseBean();
        String result = "";
        try {
            URL url = new URL( urlString );
            HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
            con.setDoOutput( true );
            con.setDoInput( true );
            con.setRequestMethod( "POST" );
            con.setUseCaches( false );
            con.setRequestProperty( "MediaType", "application/octet-stream" );
            con.setRequestProperty( "Content-Type", "application/octet-stream" );
            con.setRequestProperty( "X-API-Key", API_KEY );
            OutputStream out = con.getOutputStream();
            InputStream inputStream = getInputStreamById( fileIds );
            byte[] data = new byte[2048];
            int len = 0;
            while ((len = inputStream.read( data )) != -1) {//将读取到的本地文件流读取到HttpsURLConnection,进行上传
                out.write( data, 0, len );
            }
            out.flush();
            inputStream.close();
            out.close();
            int code = con.getResponseCode(); //获取post请求返回状态
            baseBean.writeLog( "请求返回状态=" + code );
            BufferedReader br = new BufferedReader( new InputStreamReader( con.getInputStream(), "UTF-8" ) );
            result = br.readLine();
            //获取请求的资源
            con.disconnect();//断开HttpsURLConnection连接
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    //获取对应的发票类型
    public static String getOrcTicketType(String category, String invoiceType) {
        String newType = "";
        switch (category) {
            case "vat":
                if ("增值税普通发票".equals( invoiceType )) {
                    newType = "0";//增值税普通发票
                } else if ("增值税专用发票".equals( invoiceType )) {
                    newType = "1";//增值税专用发票
                } else if ("增值税电子普通发票".equals( invoiceType )) {
                    newType = "14";//增值税电子普通发票
                }
                break;//增值税普通发票
            case "vat_roll":
                newType = "15";
                break;//增值税发票卷票
            case "quota_invoice":
                newType = "4";
                break;//定额发票
            case "machine_invoice":
                newType = "2";
                break;//机打发票
            case "vehicle_invoice":
                newType = "11";
                break;//机动车销售统一发票
            case "taxi_ticket":
                newType = "6";
                break;//出租车票
            case "train_ticket":
                newType = "7";
                break;//火车票
            case "air_ticket":
                newType = "13";
                break;//航空运输电子客票行程单
            case "pass_ticket":
                newType = "8";
                break;//过路费发票
            case "bus_ticket":
                newType = "9";
                break;//客运汽车（含船票）
            case "small_ticket":
                newType = "12";
                break;//国际小票
            case "others":
                newType = "18";
                break;//其他发票
        }
        return newType;
    }

    //发票验真接口
    public static JSONObject getInvoiceValidate(String urlString, String API_KEY, JSONObject params) {
        Map<String, String> headers = new HashMap<>();
        JSONObject jsonObject = new JSONObject();
        headers.put( "MediaType", "application/octet-stream" );
        headers.put( "Content-Type", "application/json" );
        headers.put( "X-API-Key", API_KEY );
        jsonObject.put( "Data", params );
        String result = httpPostRaw( urlString, jsonObject.toJSONString(), headers, "UTF-8" );
        JSONObject resultJson = JSONObject.parseObject( result );//发票识别的具体信息
        return resultJson;
    }

    //发送 http post 请求，参数以原生字符串进行提交
    public static String httpPostRaw(String url, String stringJson, Map<String, String> headers, String encode) {
        if (encode == null) {
            encode = "utf-8";
        }
        String content = null;
        CloseableHttpResponse httpResponse = null;
        CloseableHttpClient closeableHttpClient = null;
        try {

            //HttpClients.createDefault()等价于 HttpClientBuilder.create().build();
            closeableHttpClient = HttpClients.createDefault();
            HttpPost httpost = new HttpPost( url );

            //设置header
            httpost.setHeader( "Content-type", "application/json" );
            if (headers != null && headers.size() > 0) {
                for (Map.Entry<String, String> entry : headers.entrySet()) {
                    httpost.setHeader( entry.getKey(), entry.getValue() );
                }
            }
            //组织请求参数
            StringEntity stringEntity = new StringEntity( stringJson, encode );
            httpost.setEntity( stringEntity );
            //响应信息
            httpResponse = closeableHttpClient.execute( httpost );
            HttpEntity entity = httpResponse.getEntity();
            content = EntityUtils.toString( entity, encode );
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                httpResponse.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {  //关闭连接、释放资源
            closeableHttpClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content;
    }

    //返回文件流   已经经过脱密、解压
    public static InputStream getInputStreamById(int imageFileId_para) {
        InputStream imagefile = null;
        try {
            RecordSet rs = new RecordSet();
            String sql = "select fileRealPath,isZip,isaesencrypt,aescode,tokenKey,storageStatus  from ImageFile where imageFileId = (select imagefileid from docimagefile where docid ='" + imageFileId_para + "')";
            rs.executeQuery( sql );
            if (rs.next()) {
                String static_fileRealPath = Util.null2String( rs.getString( "fileRealPath" ) );
                String static_isZip = Util.null2String( rs.getString( "isZip" ) );
                int static_isaesencrypt = Util.getIntValue( rs.getString( "isaesencrypt" ), 0 );
                String static_aescode = Util.null2String( rs.getString( "aescode" ) );
                String static_tokenKey = Util.null2String( rs.getString( "tokenKey" ) );
                String static_storageStatus = Util.null2String( rs.getString( "storageStatus" ) );
                boolean isonlyAliOSS = false;
                if (!static_tokenKey.equals( "" ) && static_storageStatus.equals( "1" ) && AliOSSObjectManager.isonlyAliOSS()) {
                    isonlyAliOSS = true;
                }

                if (isonlyAliOSS) {
                    imagefile = weaver.alioss.AliOSSObjectUtil.downloadFile( static_tokenKey );
                } else {
                    if (static_fileRealPath != null && !static_fileRealPath.equals( "" )) {
                        File thefile = new File( static_fileRealPath );
                        if (static_isZip.equals( "1" )) {
                            ZipInputStream zin = new ZipInputStream( new FileInputStream( thefile ) );
                            if (zin.getNextEntry() != null)
                                imagefile = new BufferedInputStream( zin );
                        } else {
                            imagefile = new BufferedInputStream( new FileInputStream( thefile ) );
                        }
                    } else {
                        ConnStatement statement = null;
                        try {
                            statement = new ConnStatement();
                            boolean isoracle = ("oracle").equals( statement.getDBType() );
                            statement.setStatementSql( "select imagefile from ImageFile where imagefileid = " + imageFileId_para );
                            statement.executeQuery();
                            if (statement.next()) {
                                if (isoracle)
                                    imagefile = new BufferedInputStream( statement.getBlobBinary( "imagefile" ) );
                                else imagefile = new BufferedInputStream( statement.getBinaryStream( "imagefile" ) );
                            }
                        } catch (Exception ex) {
                        } finally {
                            try {
                                if (statement != null) statement.close();
                            } catch (Exception ex) {
                            }
                        }
                    }
                    if (static_isaesencrypt == 1) {
                        imagefile = AESCoder.decrypt( imagefile, static_aescode );
                    }

                }
            }


        } catch (Exception ex) {

        }
        return imagefile;
    }

    //获取当前登录者的部门和分部
    public static Map<String, String> getDepartAndSub(String userid) {
        Map<String, String> map = new HashMap<>();
        RecordSet rs = new RecordSet();
        rs.executeQuery( "select departmentid,subcompanyid1 from hrmresource where id='" + userid + "'" );
        rs.next();
        String departmentid = Util.null2String( rs.getString( "departmentid" ) );
        String subcompanyid1 = Util.null2String( rs.getString( "subcompanyid1" ) );
        map.put( "departmentid", departmentid );
        map.put( "subcompanyid1", subcompanyid1 );
        return map;
    }

    //获取验真发票类型
    public static String getYZTicketType(String invoiceType) {
        String newinvoiceType = "";
        switch (invoiceType) {
            case "0":
                newinvoiceType = "04";
                break;//增值税普通发票
            case "1":
                newinvoiceType = "01";
                break;//增值税专用发票
            case "14":
                newinvoiceType = "10";
                break;//增值税电子普通发票
            case "11":
                newinvoiceType = "03";
                break;//机动车销售统一发票
            case "15":
                newinvoiceType = "11";
                break;//增值税普通发票（卷式）
        }
        return newinvoiceType;
    }

    //根据logid获取ID
    public static int getLogid2Id(String logId) {
        RecordSet rs = new RecordSet();
        int id = 0;
        rs.executeQuery( "select id from uf_fpxx where logid='" + logId + "'" );
        if (rs.next()) {
            id = Util.getIntValue( rs.getString( "id" ) );
        }
        return id;
    }

    //转换发票日期
    public static String transInvoiceDate(String invoiceDate) {
        String newinvoiceDate = "";
        if (invoiceDate.contains( "年" )) {
            String b1 = invoiceDate.replace( "年", "-" );
            String b2 = b1.replace( "月", "-" );
            newinvoiceDate = b2.replace( "日", " " ).trim();
        } else {
            newinvoiceDate = invoiceDate;
        }
        return newinvoiceDate;
    }

    //判断是否重复上传
    public static boolean isRepeatCode(String repeatCode) {
        RecordSet rs = new RecordSet();
        boolean flag = true;
        rs.executeQuery( "select id from uf_fpxx where concat(fpdm,fphm)='" + repeatCode + "'" );
        if (rs.next()) {
            flag = false;
        }
        return flag;
    }

    //发票认证
    public static void invoicerecertify(String invoiceType, String invoiceCode, String invoiceNum, String invoiceDate, String totalAmount, String checkCode, String purchaserRegisterNum,String purchaserName) {
        BaseBean baseBean = new BaseBean();
        String YZ_API_KEY = baseBean.getPropValue( "langchao", "YZ_API_KEY" );
        String yz_url = baseBean.getPropValue( "langchao", "yz_url" );
        RecordSet rs = new RecordSet();
        String recertifyCode = invoiceCode + invoiceNum;
        JSONObject params = new JSONObject();
        String newinvoiceType = getYZTicketType( invoiceType );
        params.put( "InvoiceType", newinvoiceType );//发票类型
        params.put( "InvoiceCode", invoiceCode );//发票代码
        params.put( "InvoiceNumber", invoiceNum );//发票号码
        params.put( "DateOfInvoice", invoiceDate );//开票日期
        params.put( "Amount", totalAmount );//未税金额
        String subCheckCode = checkCode.length() >= 6 ? checkCode.substring( checkCode.length() - 6 ) : checkCode;
        params.put( "CheckCode", subCheckCode );//校验码后六位
        params.put( "TaxpayerIDNo", purchaserRegisterNum );//税号
        baseBean.writeLog( "发票验真参数：" + params.toJSONString() );
        JSONObject returnJson = getInvoiceValidate( yz_url, YZ_API_KEY, params );
        JSONObject ReturnInfo = JSONObject.parseObject( returnJson.getString( "ReturnInfo" ) );
        String Code = ReturnInfo.getString( "Code" );
        String Message = ReturnInfo.getString( "Message" );
        baseBean.writeLog( "验真接口返回----Code=" + Code + ", Message=" + Message );
        JSONObject Data = JSONObject.parseObject( returnJson.getString( "Data" ) );
        boolean isFpjsh =  getQueryFpttjsh(purchaserName,newinvoiceType);
        if ("01".equals( newinvoiceType )) {
            boolean isdzkyz = getInvoiceStoreQuery( invoiceNum, invoiceCode, purchaserRegisterNum );
            if ("0".equals( Code ) && isdzkyz && isFpjsh) {//验真通过
                rs.executeUpdate( "update uf_fpxx set fpzw='0' where concat(fpdm,fphm)='" + recertifyCode + "'" );
                insertXhqdInfo( Data );
            } else {//验真不通过
                rs.executeUpdate( "update uf_fpxx set fpzw='1' where concat(fpdm,fphm)='" + recertifyCode + "'" );
            }
        } else {
            if ("0".equals( Code )&& isFpjsh) {//验真通过
                if ("03".equals( newinvoiceType )) {
                    rs.executeUpdate( "update uf_fpxx set fpzw='0' where concat(fpdm,fphm)='" + recertifyCode + "'" );
                    insertVehicleXhqdInfo(Data);
                }else {
                    rs.executeUpdate( "update uf_fpxx set fpzw='0' where concat(fpdm,fphm)='" + recertifyCode + "'" );
                    insertXhqdInfo( Data );
                }

            } else {//验真不通过
                rs.executeUpdate( "update uf_fpxx set fpzw='1' where concat(fpdm,fphm)='" + recertifyCode + "'" );
            }
        }
    }

    //插入销货清单信息
    public static void insertXhqdInfo(JSONObject data) {
        RecordSet rs = new RecordSet();
        String VeriTime = Util.null2String( data.getString( "VeriTime" ) );
        String SellerAddressPhoneNo = Util.null2String( data.getString( "SellerAddressPhoneNo" ) );
        String VeriCount = Util.null2String( data.getString( "VeriCount" ) );
        String TaxAmount = isNumberType( Util.null2String( data.getString( "TaxAmount" ) ) );
        String BuyerAddressPhoneNo = Util.null2String( data.getString( "BuyerAddressPhoneNo" ) );
        String SellerBankAccount = Util.null2String( data.getString( "SellerBankAccount" ) );
        String CheckCode = Util.null2String( data.getString( "CheckCode" ) );
        String BuyerName = Util.null2String( data.getString( "BuyerName" ) );
        String InvoiceCode = Util.null2String( data.getString( "InvoiceCode" ) );
        String InvoiceNumber = Util.null2String( data.getString( "InvoiceNumber" ) );
        String BuyerBankAccount = Util.null2String( data.getString( "BuyerBankAccount" ) );
        String Comment1 = Util.null2String( data.getString( "Comment" ) );
        String PricePlusTaxes = isNumberType( Util.null2String( data.getString( "PricePlusTaxes" ) ) );
        String SellerTaxpayerNo = Util.null2String( data.getString( "SellerTaxpayerNo" ) );
        String Amount = isNumberType( Util.null2String( data.getString( "Amount" ) ) );
        String BuyerTaxpayerNo = Util.null2String( data.getString( "BuyerBankAccount" ) );
        String InvoiceType = Util.null2String( data.getString( "InvoiceType" ) );
        String InvalidFlag = Util.null2String( data.getString( "InvalidFlag" ) );
        String DateOfInvoice = Util.null2String( data.getString( "DateOfInvoice" ) );
        String MechineCode = Util.null2String( data.getString( "MechineCode" ) );
        String SellerName = Util.null2String( data.getString( "SellerName" ) );
        String verifityCode = CheckCode + MechineCode;
        rs.executeQuery( "select id from uf_xhqd where concat(checkcode,MechineCode)='" + verifityCode + "'" );
        if (!rs.next()) {
            String sql = "insert into uf_xhqd(VeriTime,SellerAddressPhoneNo,VeriCount,TaxAmount,BuyerAddressPhoneNo,SellerBankAccount," +
                    "CheckCode,BuyerName,InvoiceCode,InvoiceNumber,BuyerBankAccount,Comment1,PricePlusTaxes,SellerTaxpayerNo," +
                    "Amount,BuyerTaxpayerNo,InvoiceType,InvalidFlag,DateOfInvoice,MechineCode,SellerName) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{VeriTime, SellerAddressPhoneNo, VeriCount, TaxAmount, BuyerAddressPhoneNo, SellerBankAccount,
                    CheckCode, BuyerName, InvoiceCode, InvoiceNumber, BuyerBankAccount, Comment1, PricePlusTaxes, SellerTaxpayerNo,
                    Amount, BuyerTaxpayerNo, InvoiceType, InvalidFlag, DateOfInvoice, MechineCode, SellerName};
            if (rs.executeUpdate( sql, params )) {
                //插入明细
                String mainid = "";
                String MergeCode = InvoiceCode + InvoiceNumber;
                rs.executeQuery( "select id from uf_xhqd where concat(InvoiceCode,InvoiceNumber)='" + MergeCode + "'" );
                if (rs.next()) {
                    mainid = Util.null2String( rs.getString( "id" ) );
                }
                JSONArray GoodsOrServices = JSONArray.parseArray( data.getString( "GoodsOrServices" ) );
                for (int i = 0; i < GoodsOrServices.size(); i++) {
                    JSONObject results = (JSONObject) GoodsOrServices.get( i );
                    String Amount1 = isNumberType( Util.null2String( results.getString( "Amount" ) ) );
                    String Sequence = Util.null2String( results.getString( "Sequence" ) );
                    String Unit = Util.null2String( results.getString( "Unit" ) );
                    String Name = Util.null2String( results.getString( "Name" ) );
                    String UnitPrice = isNumberType( Util.null2String( results.getString( "UnitPrice" ) ) );
                    String TaxAmount1 = isNumberType( Util.null2String( results.getString( "TaxAmount" ) ) );
                    String Specifications = Util.null2String( results.getString( "Specifications" ) );
                    String Number1 = Util.null2String( results.getString( "Number" ) );
                    String TaxRate = isNumberType( Util.null2String( results.getString( "TaxRate" ) ) );
                    String ProjectName = Util.null2String( results.getString( "ProjectName" ) );
                    String PlateNo = Util.null2String( results.getString( "PlateNo" ) );
                    String Vehicletype = Util.null2String( results.getString( "Vehicletype" ) );
                    String PassageDateBegin = Util.null2String( results.getString( "PassageDateBegin" ) );
                    String PassageDateEnd = Util.null2String( results.getString( "PassageDateEnd" ) );
                    String sql1 = "insert into uf_xhqd_dt1(mainid,Amount1,Sequence,Unit,Name,UnitPrice,TaxAmount1,Specifications,Number1,TaxRate," +
                            "ProjectName,PlateNo,Vehicletype,PassageDateBegin,PassageDateEnd) " +
                            "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    Object[] param = new Object[]{mainid, Amount1, Sequence, Unit, Name, UnitPrice, TaxAmount1, Specifications, Number1, TaxRate,
                            ProjectName, PlateNo, Vehicletype, PassageDateBegin, PassageDateEnd};
                    rs.executeUpdate( sql1, param );
                }
            }

        }
    }

    //插入机车销货清单信息
    public static void insertVehicleXhqdInfo(JSONObject data) {
        RecordSet rs = new RecordSet();
        String InvoiceType = Util.null2String( data.getString( "InvoiceType" ) );
        String InvoiceCode = Util.null2String( data.getString( "InvoiceCode" ) );
        String InvoiceNumber = Util.null2String( data.getString( "InvoiceNumber" ) );
        String DateOfInvoice = Util.null2String( data.getString( "DateOfInvoice" ) );
        String Amount = Util.null2String( data.getString( "Amount" ) );
        String TaxAmount = Util.null2String( data.getString( "TaxAmount " ) );
        String PricePlusTaxes = Util.null2String( data.getString( "PricePlusTaxes " ) );
        String BuyerName = Util.null2String( data.getString( "BuyerName " ) );
        String BuyerTaxpayerNo = Util.null2String( data.getString( "BuyerTaxpayerNo " ) );
        String BuyerAddressPhoneNo = Util.null2String( data.getString( "BuyerAddressPhoneNo " ) );
        String BuyerBankAccount = Util.null2String( data.getString( "BuyerBankAccount " ) );
        String SellerName = Util.null2String( data.getString( "SellerName " ) );
        String SellerTaxpayerNo = Util.null2String( data.getString( "SellerTaxpayerNo " ) );
        String SellerAddressPhoneNo = Util.null2String( data.getString( "SellerAddressPhoneNo " ) );
        String SellerBankAccount = Util.null2String( data.getString( "SellerBankAccount " ) );
        String Comment1 = Util.null2String( data.getString( "Comment " ) );
        String MechineCode = Util.null2String( data.getString( "MechineCode " ) );
        String CheckCode = Util.null2String( data.getString( "CheckCode " ) );
        String InvalidFlag = Util.null2String( data.getString( "InvalidFlag " ) );
        String IDCardNo = Util.null2String( data.getString( "IDCardNo " ) );
        String VehicleType = Util.null2String( data.getString( "VehicleType " ) );
        String LicenseType = Util.null2String( data.getString( "LicenseType " ) );
        String ProductionPlace = Util.null2String( data.getString( "ProductionPlace " ) );
        String CertificateNo = Util.null2String( data.getString( "CertificateNo " ) );
        String CommodityInspectionNo = Util.null2String( data.getString( "CommodityInspectionNo" ) );
        String EngineNo = Util.null2String( data.getString( "EngineNo " ) );
        String VIN = Util.null2String( data.getString( "VIN " ) );
        String ImportCerNo = Util.null2String( data.getString( "ImportCerNo" ) );
        String Authority = Util.null2String( data.getString( "Authority " ) );
        String AuthorityName = Util.null2String( data.getString( "AuthorityName " ) );
        String TaxPaymentCerNo = Util.null2String( data.getString( "TaxPaymentCerNo " ) );
        String Tonnage = Util.null2String( data.getString( "Tonnage " ) );
        String Passengers = Util.null2String( data.getString( "Passengers " ) );
        String TaxRate = Util.null2String( data.getString( "TaxRate " ) );
        String SellerPhone = Util.null2String( data.getString( "SellerPhone " ) );
        String SellerAccount = Util.null2String( data.getString( "SellerAccount " ) );
        String SellerAddress = Util.null2String( data.getString( "SellerAddress " ) );
        String SellerBank = Util.null2String( data.getString( "SellerBank " ) );
        String verifityCode = CheckCode + MechineCode;
        rs.executeQuery( "select id from uf_jcxhqd where concat(checkcode,MechineCode)='" + verifityCode + "'" );
        if (!rs.next()) {
            String sql = "insert into uf_jcxhqd(invoicetype,invoicecode,invoicenumber,dateofinvoice,amount,taxamount,priceplustaxes,\n" +
                    "buyername,buyertaxpayerno,buyeraddressphoneno,buyerbankaccount,sellername,sellertaxpayerno,selleraddressphoneno,\n" +
                    "sellerbankaccount,comment1,mechinecode,checkcode,invalidflag,idcardno,vehicletype,licensetype,productionplace,\n" +
                    "certificateno,commodityinspectionno,engineno,vin,importcerno,authority,authorityname,taxpaymentcerno,tonnage,\n" +
                    "passengers,taxrate,sellerphone,selleraccount,selleraddress,sellerbank) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{InvoiceType, InvoiceCode, InvoiceNumber, DateOfInvoice, Amount, TaxAmount, PricePlusTaxes, BuyerName, BuyerTaxpayerNo,
                    BuyerAddressPhoneNo, BuyerBankAccount, SellerName, SellerTaxpayerNo, SellerAddressPhoneNo, SellerBankAccount, Comment1,
                    MechineCode, CheckCode, InvalidFlag, IDCardNo, VehicleType, LicenseType, ProductionPlace, CertificateNo, CommodityInspectionNo,
                    EngineNo, VIN, ImportCerNo, Authority, AuthorityName, TaxPaymentCerNo, Tonnage, Passengers, TaxRate, SellerPhone, SellerAccount,
                    SellerAddress, SellerBank};
            rs.executeUpdate( sql, params );
        }
}

    //判断是否发票认证
    public static boolean isInvoicerecertify(String repeatCode) {
        RecordSet rs = new RecordSet();
        boolean flag = false;
        rs.executeQuery( "select fpzw from uf_fpxx where concat(fpdm,fphm)='" + repeatCode + "'" );
        if (rs.next()) {
            String fpzw = Util.null2String( rs.getString( "fpzw" ) );//发票真伪
            flag = "0".equals( fpzw ) ? true : false;
        }
        return flag;
    }

    //判断发票税额是否是数字
    public static String isNumberType(String str) {
        Boolean strResult = str.matches( "-?[0-9]+.?[0-9]*" );
        String newStr = strResult == true ? str : "0";
        return newStr;
    }

    //插入上传影像信息
    public static boolean insertImageInfo(int yxscr, int scyxid, String scrq) {
        RecordSet rs = new RecordSet();
        UUID MR_UUID = UUID.randomUUID();
        String uuid = MR_UUID.toString(); //唯一标志
        String sfsbcg = "1";
        String yxsl = "1";
        String sql = "insert into uf_scyxk(yxscr,scyxid,scrq,sfsbcg,yxsl,uuid) values (?,?,?,?,?,?)";
        Object[] params = new Object[]{yxscr, scyxid, scrq, sfsbcg, yxsl, uuid};
        boolean flag = rs.executeUpdate( sql, params );
        return flag;
    }

    //更新上传影像信息
    public static boolean updateImageInfo(int yxscr, int scyxid, String scrq) {
        RecordSet rs = new RecordSet();
        String sql = "update uf_scyxk set sfsbcg='0' where yxscr=? and scyxid=? and scrq=?";
        Object[] params = new Object[]{yxscr, scyxid, scrq};
        boolean flag = rs.executeUpdate( sql, params );
        return flag;
    }

    //查询底账库是否存在发票
    public static boolean getInvoiceStoreQuery(String invoicenum, String invoicecode, String buyertaxno) {
        boolean flag = true;
        BaseBean baseBean = new BaseBean();
        String dzk_url = baseBean.getPropValue( "langchao", "dzk_url" );
        JSONObject dataJson = new JSONObject();
        dataJson.put( "INVOICENUM", invoicenum );
        dataJson.put( "INVOICECODE", invoicecode );
        dataJson.put( "BUYERTAXNO", buyertaxno );
        JSONObject reustl = HttpRequestUtil.sendPostHttpRequest( dzk_url, dataJson.toJSONString() );
        baseBean.writeLog( "底账库接口返回Result=" + reustl.toJSONString() );
        String code = reustl.getString( "code" );
        String msg = reustl.getString( "msg" );
        if (!"1".equals( code ) || !"".equals( msg )) {
            flag = false;
        }
        return flag;
    }

    //查询本地是否存在发票及税号
    public static boolean getQueryFpttjsh(String fpmc,String fpsh){
        RecordSet rs = new RecordSet();
        boolean flag = true;
        String sql = "select gsmc,sh from uf_fpttjsh where gsmc=? and sh=?";
        rs.executeQuery(sql,fpmc,fpsh);
        if(!rs.next()){
            flag = false;
        }
        return flag;
    }

    //增值税电子普通发票/卷票
    public static boolean getTicketType_var(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[var]" );
        boolean flag = false;
        String invoiceType = Util.null2String( details.getString( "invoiceType" ) );
        invoiceType = getOrcTicketType( category, invoiceType );
        String logId = Util.null2String( details.getString( "logId" ) );
        String invoiceCode = Util.null2String( details.getString( "invoiceCode" ) );//发票代码
        String invoiceNum = Util.null2String( details.getString( "invoiceNum" ) );//发票号码
        String invoiceDate = transInvoiceDate( Util.null2String( details.getString( "invoiceDate" ) ) );
        String totalAmount = isNumberType( Util.null2String( details.getString( "totalAmount" ) ) );//不含税金额
        String totalTax = isNumberType( Util.null2String( details.getString( "totalTax" ) ) );//税额
        String amountInFiguers = isNumberType( Util.null2String( details.getString( "amountInFiguers" ) ) );//含税金额
        String sellerName = Util.null2String( details.getString( "sellerName" ) );//售方名称
        String sellerRegisterNum = Util.null2String( details.getString( "sellerRegisterNum" ) );//售方税号
        String checkCode = Util.null2String( details.getString( "checkCode" ) );
        String purchaserName = Util.null2String( details.getString( "purchaserName" ) );//购方名称
        String purchaserRegisterNum = Util.null2String( details.getString( "purchaserRegisterNum" ) );//购方税号
        String sl = "";
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( invoiceCode + invoiceNum )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,xfdwsh,fpzt,fpyx,fpzw,logid,sellerRegisterNum,gmfmc,checkCode,formmodeid," +
                    "modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] param = new Object[]{userid, currentDate, supsubcom, department, invoiceCode, invoiceNum, invoiceDate,
                    invoiceType, amountInFiguers, totalAmount, totalTax, sl, sellerName, sellerRegisterNum, fpzt, fileId, fpzw, logId,
                    purchaserName, purchaserRegisterNum, checkCode, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            if (rs.executeUpdate( sql, param )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                JSONArray commodities = JSONArray.parseArray( Util.null2String( details.getString( "commodities" ) ) );
                for (int j = 0; j < commodities.size(); j++) {
                    JSONObject jsonObject = (JSONObject) commodities.get( j );
                    String name = Util.null2String( jsonObject.getString( "name" ) );//名称
                    String type = Util.null2String( jsonObject.getString( "type" ) );//类型
                    String unit = Util.null2String( jsonObject.getString( "unit" ) );//单位
                    String num = Util.null2String( jsonObject.getString( "num" ) );//数量
                    String price = Util.null2String( jsonObject.getString( "price" ) );//价格
                    String amount = Util.null2String( jsonObject.getString( "amount" ) );//总额
                    String taxRate = isNumberType( Util.null2String( jsonObject.getString( "taxRate" ) ) ).replace( "%", "" );//税率
                    String tax = Util.null2String( jsonObject.getString( "tax" ) );//税额
                    rs.executeQuery( "select sl,id from uf_fpxx where logid='" + logId + "'" );
                    if (rs.next()) {
                        String mainid = Util.null2String( rs.getString( "id" ) );
                        sl = Util.null2String( rs.getString( "sl" ) );
                        String sql1 = "insert into uf_fpxx_dt1 (mainid,hwhyslwfwmc,ggxh,dw,sl,dj,je,slv,se) " +
                                "values (?,?,?,?,?,?,?,?,?)";
                        rs.executeUpdate( sql1, new Object[]{mainid, name, type, unit, num, price, amount, taxRate, tax} );
                        rs.writeLog( sql1, String.join( ",", mainid, name, type, unit, num, price, amount, taxRate, tax ) );
                    }
                    if ("".equals( sl )) {
                        rs.executeUpdate( "update uf_fpxx set sl ='" + taxRate + "' where logid='" + logId + "'" );
                    }
                    //更新税率和税额
                }
                if (!isInvoicerecertify( invoiceCode + invoiceNum )) {//发票是否验真
                    invoicerecertify( invoiceType, invoiceCode, invoiceNum, invoiceDate, totalAmount, checkCode, purchaserRegisterNum,purchaserName );
                }
                flag = true;
            }
        }
        return flag;
    }

    //机打发票
    public static boolean getTicketType_machine_invoice(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[machine_invoice]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String commodityName = Util.null2String( details.getString( "commodityName" ) );
        String invoiceCode = Util.null2String( details.getString( "invoiceCode" ) );
        String invoiceDate = transInvoiceDate( Util.null2String( details.getString( "invoiceDate" ) ) );
        String invoiceNum = Util.null2String( details.getString( "invoiceNum" ) );
        String totalTax = isNumberType( Util.null2String( details.getString( "totalTax" ) ) );
        String bhsje = "";
        String se = "";
        String sl = "";
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( invoiceCode + invoiceNum )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] param = new Object[]{userid, currentDate, supsubcom, department, invoiceCode, invoiceNum, invoiceDate,
                    oaFplx, totalTax, bhsje, se, sl, commodityName, fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, param );
            if (rs.executeUpdate( sql, param )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
        }
        return flag;
    }

    ///机动车销售统一发票
    public static boolean getTicketType_vehicle_invoice(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[vehicle_invoice]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String invoiceCode = Util.null2String( details.getString( "invoiceCode" ) );
        String invoiceNum = Util.null2String( details.getString( "invoiceNum" ) );
        String invoiceDate = transInvoiceDate( Util.null2String( details.getString( "invoiceDate" ) ) );
        String saler = Util.null2String( details.getString( "saler" ) );
        String taxRate = Util.null2String( details.getString( "taxRate" ) );
        String tax = isNumberType( Util.null2String( details.getString( "tax" ) ) );
        String price = isNumberType( Util.null2String( details.getString( "price" ) ) );
        String payerCode = isNumberType( Util.null2String( details.getString( "payerCode" ) ) );
        double bhsje = Double.valueOf( price ) - Double.valueOf( tax );
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( invoiceCode + invoiceNum )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{userid, currentDate, supsubcom, department, invoiceCode, invoiceNum,
                    invoiceDate, oaFplx, price, bhsje, taxRate, tax, saler, fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, params );
            if (rs.executeUpdate( sql, params )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
            if (!isInvoicerecertify( invoiceCode + invoiceNum )) {//发票是否验真
                invoicerecertify( oaFplx, invoiceCode, invoiceNum, invoiceDate, price, "", payerCode,"");
            }
        }
        return flag;
    }

    //航空运输电子客票行程单
    public static boolean getTicketType_air_ticket(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[air_ticket]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String date = transInvoiceDate( Util.null2String( details.getString( "date" ) ) );
        String ticketRates = isNumberType( Util.null2String( details.getString( "ticketRates" ) ) );
        String ticketNumber = Util.null2String( details.getString( "ticketNumber" ) );
        double se = (Double.valueOf( ticketRates ) - 50) / 1.09 * 0.09;//税额
        String sl = "9";//税率
        double bhsje = Double.valueOf( ticketRates ) - se;//不含税金额
        String fpzt = "0";
        String fpzw = "2";
        String xfdwmc = "";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( "" + ticketNumber )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{userid, currentDate, supsubcom, department, "", ticketNumber, date, oaFplx,
                    ticketRates, bhsje, se, sl, xfdwmc, fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, params );
            if (rs.executeUpdate( sql, params )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
        }
        return flag;
    }

    //出租车票
    public static boolean getTicketType_taxi_ticket(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[taxi_ticket]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String date = transInvoiceDate( Util.null2String( details.getString( "date" ) ) );
        String invoiceCode = Util.null2String( details.getString( "invoiceCode" ) );
        String fare = isNumberType( Util.null2String( details.getString( "fare" ) ) );
        String invoiceNum = Util.null2String( details.getString( "invoiceNum" ) );
        String bhsje = "";
        String se = "";
        String sl = "";
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( invoiceCode + invoiceNum )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{userid, currentDate, supsubcom, department, invoiceCode, invoiceNum, date, oaFplx, fare, bhsje,
                    se, sl, "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, params );
            if (rs.executeUpdate( sql, params )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
        }
        return flag;
    }

    //火车票
    public static boolean getTicketType_train_ticket(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[train_ticket]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String date = transInvoiceDate( Util.null2String( details.getString( "date" ) ) );
        String ticketNum = Util.null2String( details.getString( "ticketNum" ) );
        String ticketRates = isNumberType( Util.null2String( details.getString( "ticketRates" ) ) );
        double se = Double.valueOf( ticketRates ) / 1.09 * 0.09;//税额
        String sl = "9";//税率
        double bhsje = Double.valueOf( ticketRates ) - se;//不含税金额
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( "" + ticketNum )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{userid, currentDate, supsubcom, department, "", ticketNum, date, oaFplx, ticketRates, bhsje,
                    se, sl, "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, params );
            if (rs.executeUpdate( sql, params )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
        }
        return flag;
    }

    //过路费发票
    public static boolean getTicketType_pass_ticket(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[pass_ticket]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String code = Util.null2String( details.getString( "code" ) );
        String number = Util.null2String( details.getString( "number" ) );
        String date = transInvoiceDate( Util.null2String( details.getString( "date" ) ) );
        String total = isNumberType( Util.null2String( details.getString( "total" ) ) );
        String bhsje = "";
        String se = "";
        String sl = "";
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( code + number )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{userid, currentDate, supsubcom, department, code, number, date, oaFplx, total, bhsje,
                    se, sl, "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, params );
            if (rs.executeUpdate( sql, params )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
        }
        return flag;
    }

    //客运汽车（含船票）
    public static boolean getTicketType_bus_ticket(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[bus_ticket]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String code = Util.null2String( details.getString( "code" ) );
        String number = Util.null2String( details.getString( "number" ) );
        String date = transInvoiceDate( Util.null2String( details.getString( "date" ) ) );
        String total = isNumberType( Util.null2String( details.getString( "total" ) ) );
        double se = Double.valueOf( total ) / 1.09 * 0.03;//税额
        String sl = "3";//税率
        double bhsje = Double.valueOf( total ) - se;//不含税金额
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        if (isRepeatCode( code + number )) {//判断是否重复--false 重复，true-不重复
            String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                    "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = new Object[]{userid, currentDate, supsubcom, department, code, number, date, oaFplx, total, bhsje,
                    se, sl, "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
            rs.writeLog( sql, params );
            if (rs.executeUpdate( sql, params )) {
                int id = getLogid2Id( logId );
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight( true );
                modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
                flag = true;
            }
        }
        return flag;
    }

    //国际小票
    public static boolean getTicketType_small_ticket(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[small_ticket]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String date = transInvoiceDate( Util.null2String( details.getString( "date" ) ) );
        String total = isNumberType( Util.null2String( details.getString( "total" ) ) );
        String tax = isNumberType( Util.null2String( details.getString( "tax" ) ) );
        double bhsje = Double.valueOf( total ) - Double.valueOf( tax );
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] params = new Object[]{userid, currentDate, supsubcom, department, logId, "", date, oaFplx, total, bhsje,
                tax, "", "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
        rs.writeLog( sql, params );
        if (rs.executeUpdate( sql, params )) {
            int id = getLogid2Id( logId );
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight( true );
            modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
            flag = true;
        }
        return flag;
    }

    //定额小票
    public static boolean getTicketType_quota_invoice(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[quota_invoice]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String invoiceCode = Util.null2String( details.getString( "invoiceCode" ) );
        String invoiceNumber = Util.null2String( details.getString( "invoiceNumber" ) );
        String invoiceRate = isNumberType( Util.null2String( details.getString( "invoiceRate" ) ) );
        String tax = "0";
        double bhsje = 0.00;
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] params = new Object[]{userid, currentDate, supsubcom, department, invoiceCode, invoiceNumber, "", oaFplx, invoiceRate, bhsje,
                tax, "", "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
        rs.writeLog( sql, params );
        if (rs.executeUpdate( sql, params )) {
            int id = getLogid2Id( logId );
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight( true );
            modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
            flag = true;
        }
        return flag;
    }

    //其他发票
    public static boolean getTicketType_others(int userid, String currentDate, String supsubcom, String department, int fileId, String formmodeid, String category, JSONObject details) {
        RecordSet rs = new RecordSet();
        rs.writeLog( "---------发票类型[others]" );
        boolean flag = false;
        String oaFplx = getOrcTicketType( category, "" );
        String logId = Util.null2String( details.getString( "logId" ) );
        String code = Util.null2String( details.getString( "code" ) );
        String number = Util.null2String( details.getString( "number" ) );
        String total = Util.null2String( details.getString( "total" ) );
        String tax = "0";
        double bhsje = 0.00;
        String fpzt = "0";
        String fpzw = "2";
        String modedatacreatertype = "0";
        String modedatacreatedate = DateUtil.getCurrentDate();
        String fullDate = DateUtil.getFullDate();
        String modedatacreatetime = fullDate.substring( 11, 19 );
        String sql = "insert into uf_fpxx(fplrr,lrrq,ssfgs,ssfrzz,fpdm,fphm,fprq,fplx,je,bhsje," +
                "se,sl,xfdwmc,fpzt,fpyx,fpzw,logid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) " +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] params = new Object[]{userid, currentDate, supsubcom, department, code, number, "", oaFplx, total, bhsje,
                tax, "", "", fpzt, fileId, fpzw, logId, formmodeid, userid, modedatacreatertype, modedatacreatedate, modedatacreatetime};
        rs.writeLog( sql, params );
        if (rs.executeUpdate( sql, params )) {
            int id = getLogid2Id( logId );
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight( true );
            modeRightInfo.editModeDataShare( userid, Integer.parseInt( formmodeid ), id );
            flag = true;
        }
        return flag;
    }

}
